﻿import com.dmotiko.bolacua.*
import com.dmotiko.general.*
import com.dmotiko.util.*
import mx.utils.Delegate;

class NavBarBolacua
extends WebSiteNavBar {
	
	private var nX:Number;
	private var nX_sep:Number;
	private var nWidth:Number;
	private var aBtns:Array;
	
	function NavBarBolacua() {
		super("btnAppear", "btnSeparator");
		this.nX = 0;
		this.nX_sep = 10;
		this.nWidth = 705;
		aBtns = [ 
				   { label: "home" , label_i: "home", section: BolacuaSite.HOME},
				   { label: "eventos & convenciones", label_i: "events & convention center", section: BolacuaSite.EVENTOS },
				   { label: "restaurante", label_i: "restaurant", section: BolacuaSite.RESTAURANT },
				   { label: "alojamiento", label_i: "rooms", section: BolacuaSite.ALOJAMIENTO },
				   { label: "tarifas & reservas", label_i: "rates & booking", section: BolacuaSite.TARIFAS },
				   { label: "como llegar", label_i: "getting there", section: BolacuaSite.COMO_LLEGAR },
				   { label: "infraestructura", label_i: "facilities", section: BolacuaSite.INFRAESTRUCTURA },
				   { label: "contacto", label_i: "contact us", section: BolacuaSite.CONTACTO }
				   ];
		this.setData(aBtns);
		BolacuaSite.getApp().setNavBar(this);
		BolacuaSite.getApp().addEventListener( WebSite.LANGUAGE_CHANGED, Delegate.create(this, lang_changed) );
	}
	
	private function lang_changed(e):Void 
	{
		this.nX = 0;
		if ( BolacuaSite.getApp().getLanguage() == BolacuaSite.SPANISH ) this.nX_sep = 10;
		else this.nX_sep = 15;
		
		this.setData( aBtns );
	}
	
	private function layoutButtons() {
		for(var i:Number = 0; i < mapBtns.length; i++){
			mapBtns[i][0]._x = nX;
			nX += mapBtns[i][0].mcBtn.txt._width;
			if(mapBtns[i][0].separator){
				mapBtns[i][0].separator._x = nX;
				mapBtns[i][0].separator._alpha = 0;
				nX += mapBtns[i][0].separator._width + this.nX_sep;
			} 
			mapBtns[i][0].show();
		}
		
		BolacuaSite.getApp().addEventListener(BolacuaSite.SECTION_CHANGED, Delegate.create(this, refreshSection));
		//para mantener la seccion activa en el refresh de idioma
		BolacuaSite.getApp().setSection( BolacuaSite.getApp().getSection() );
	}
	
	private function refreshSection() {
		var sSection:String = BolacuaSite.getApp().getSection();
		for (var i:Number = 0; i < mapBtns.length; i++) {
			if ( mapBtns[i][0].getData().section == sSection ) {
				mapBtns[i][0].mcBtn.onRollOver();
				mapBtns[i][0].mcBtn.onRelease();
			}
		}
	}
	
	private function childChanged(evnt):Void {
		if(evnt.description == "release"){
			if(this.getActiveBtn() != evnt.target){
				mcActiveBtn.getChild("mcBtn").setActive(false);
				this.setActiveBtn(evnt.target);
			}
			mcActiveBtn.getChild("mcBtn").setActive(true);
			if(BolacuaSite.getApp().getSection() != evnt.target.mcBtn.data.section){
				BolacuaSite.getApp().setSection( evnt.target.mcBtn.data.section );
			}
		}
		if(evnt.target != mcLastChild){
			mcLastChild.getChild("mcBtn").onRollOut();
			mcLastChild = evnt.target;
		}
	}
	
	
}